home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / newring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-24  |  2.0 KB  |  84 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12.  
  13. #define  MAIN_PROG
  14. #include <comm.h>   /*     This file defines certain constants, and declares
  15.             some global variables used by the message passing
  16.             routines.  */
  17.  
  18. #ifdef HPUX
  19. #   define srandom srand
  20. #   define random rand
  21. #endif
  22.  
  23. #ifndef RNEIGH
  24. #   define RNEIGH(x,tot)    ((x<tot)?x+1:1) /* right neighbor of x in ring */
  25. #endif
  26.  
  27. #ifndef LNEIGH
  28. #   define LNEIGH(y,tot)    ((y==1)?tot:y-1)
  29. #endif
  30.  
  31. #define MAXTIME 12                        /* Maximum computation time in sec.*/
  32. #define INT_SZ sizeof(int)
  33.  
  34. char *progname;
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.   int ntasks, my_tid, i;
  41.   int comp_time, intime, timeleft, iter_cnt;
  42.   int sendto_task, rcvfrom_task;
  43.  
  44.   init_task(argv);    /* Initialization is required for all tasks in every
  45.              application */
  46.   pfs_debug=0;
  47.   my_tid = gettid(); 
  48.   if (my_tid == -1) {
  49.     io_printf(" task could not get its tid!", (char *)0);
  50.     exit(1);
  51.   }
  52.   
  53.   timeleft = MAXTIME;
  54.   ntasks = numtasks();   /* Total number of tasks in this job */
  55.   
  56.   sendto_task = RNEIGH(my_tid,ntasks);   /* My right neighbor in the ring */
  57.   rcvfrom_task = LNEIGH(my_tid,ntasks);
  58.  
  59.   srandom(getjid() + 10 * my_tid);
  60.  
  61.   for (iter_cnt = 1; iter_cnt <= 5; iter_cnt++) {
  62.     /* Number of seconds for which computation is  performed */
  63.     comp_time = random()%5 + 5;   
  64.     
  65.     sleep(comp_time);         /* Simulate computation by sleeping */
  66.     
  67.     io_printf("completed iteraton %d. ...sending to task %d and rcving from task %d", iter_cnt, sendto_task, rcvfrom_task, (char *)0);
  68.     
  69.     /* Send and receive messages */ 
  70.     for (i = 1; i < ntasks; i++) {
  71.       vsendrecv (rcvfrom_task, ANY_TAG, &intime, INT_SZ,
  72.         sendto_task,  ANY_TAG, &comp_time, INT_SZ);
  73.     
  74.       comp_time = intime;
  75.       sleep(comp_time);
  76.     } 
  77.   }
  78.  
  79.   io_printf("done.\n", (char *)0 );
  80.   
  81.   exit(0);
  82. }
  83.  
  84.